<?php
if ( !defined('IN_ADMINCP') || !defined('IN_SEC') ){
	exit('Access Denied.');
}


$companyid = intval(abs($_G['gp_companyid']));
$departmentid = intval(abs($_G['gp_departmentid']));
//如果传入$id，则检测管理员是否存在，不存在提示错误
$adminid = $admincp->adminid;
$group = $admincp->groups[$admincp->admin['groupid']];
$id = abs(intval($_G['gp_id']));

if( $id && !$customer = fetch('customer', $id) ){
	$admincp->cpmsg('客户不存在');
}


$admin = fetch('admincp_member',array('sale_id'=>$adminid,'cus_id'=>$id));
	// $account = new admincp_account();
	// $admin['realneme'] = "test0838";
	// $update = $account->edit($admin);
	// var_dump($update);
	// exit();


if ( is_post() ){
	
	if( !confirm_password($admincp->admin) ){
		$admincp->cpmsg('密码不正确！授权操作失败！');
	}

	$groupid = intval(17);
	$account = new admincp_account();
	if ( !empty($admin) ){

		if( $admin['id'] != 1 ){
			$admin['departmentid'] = intval(12);
			$admin['companyid'] = intval(1);
		}
		$admin['mobile'] = $_G['gp_phone'];
		$admin['realname'] = $_G['gp_realname'];
		$admin['sale_id'] = $adminid;
		$update = $account->edit($admin);
	}else{
		$update = $account->register();
	}
	$admincp->success();
}

?>